'use strict'
import React, { Component } from 'react';// 各种包一定要注意导入
import {
    Platform,
    StyleSheet,
    Text,
    View,
    NativeModules,
    TouchableOpacity,
    ToastAndroid,
    Image,
    TouchableWithoutFeedback,
    BackHandler
} from 'react-native';
import { Toast } from 'teaset'
import sha256 from 'sha256';

import NavigatorBar from '../../common/NavigationBar';

const Dimensions = require('Dimensions');
const { width, height } = Dimensions.get('window');

var that;

class ChatScreen extends Component {


    constructor(props) {
        super(props);
        global.log(props.navigation, "45676545654");
        this.params = props.navigation.state.params;
        that = this;
        // console.log(this.params, "================params=================")
        this.showText=this.params.payCourseInfo.toPage == 'DetailLesson' ? "程" : '时'
       
    }


    handleBack() {
        // alert(3);
        that._onPressSubmit();
        return true;
    }

    componentDidMount() {
        BackHandler.addEventListener('hardwareBackPress', that.handleBack);
    }

    componentWillUnmount() {

        BackHandler.removeEventListener('hardwareBackPress', that.handleBack)
    }

    _onPressSubmit() {

        // var pwd = sha256("111111"); // 必须是字符串  数据就错的
        // Toast.message("跳转页面,待定");

        var payCourseInfo = this.params.payCourseInfo;

        var toParams = {
            fromPaySucess: true
        };

        if (payCourseInfo.toPage == "DetailLesson") {
            toParams['courseId'] = payCourseInfo.BASICINFO.COURSE_ID;
        }

        if (payCourseInfo.toPage == "KeShiIndex") {
            toParams['id'] = payCourseInfo.LISTCOURSE[0].COURSE_ID
        }


        this.props.navigation.navigate(payCourseInfo.toPage, toParams);
    

    }

    // 渲染按钮
    renderLeftButton(image) {
        return <TouchableOpacity
            style={[global.CommonStyleSheet.NavLeftButton]}
            onPress={() => {
                this.props.navigation.goBack();
            }}>
            <Image
                style={{ width: 34, height: 34 }}
                source={image} />
        </TouchableOpacity>;
    }

    render() {

        return (
            <View style={styles.container}>

                <NavigatorBar
                    title={'支付成功'}
                    style={styles.navigatorBar}
                // leftButton={this.renderLeftButton(require('../../assets/imgs/back.png'))}
                />

                <View style={styles.one}>
                    <Text style={styles.bigTips}>报名成功</Text>
                    <Text style={styles.smallTips}>可在:我的-我已报名的课程中查看已报名课{this.showText}</Text>
                </View>

                <TouchableWithoutFeedback onPress={() => { this._onPressSubmit() }}>
                    <Text style={[styles.submitBtn]} >查看课{this.showText}</Text>
                </TouchableWithoutFeedback>





            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F2F2F2'
    },
    one: {
        width: width,
        height: width * 0.5,
        backgroundColor: 'white',
        justifyContent: 'center',
        alignItems: 'center'
    },
    bigTips: {
        height: 50,
        color: '#333',
        fontSize: 20
    },
    smallTips: {
        height: 40,
        color: '#999',
        fontSize: 14
    },
    submitBtn: {
        paddingTop: 14,
        paddingBottom: 14,
        color: '#fff',
        textAlign: 'center',
        backgroundColor: '#FF6F26',
        borderRadius: 32,
        borderWidth: 1,
        borderColor: '#FF6F26',
        fontSize: 14,
        marginTop: 30,
        width: width - 60,
        marginLeft: 30,
    }
});

export default ChatScreen;